package com.cap.bts.crmdp.dealer.masterinfo.dao.impl;

import java.util.List;

import javax.inject.Inject;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;

import com.cap.bts.crmdp.dealer.masterinfo.dao.IMasterFileDao;
import com.cap.bts.crmdp.dealer.masterinfo.domain.MasterFileModel;
import com.cap.bts.crmdp.dealer.masterinfo.dto.MasterFileDto;
import com.cap.bts.framework.common.dao.impl.BaseDaoImpl;
import com.cap.bts.framework.common.exception.AppException;

@Repository("iMasterFileDao")
public class MasterFileDaoImpl extends BaseDaoImpl<MasterFileModel, Long> implements IMasterFileDao {

    @Inject
    public MasterFileDaoImpl(@Value("com.cap.bts.crmdp.dealer.masterinfo.domain.MasterFileModel") Class<MasterFileModel> clazz) {
        super(clazz);

    }

    /**
     * 根据文件名称查询已经同步过的master文件
     * @see com.cap.bts.crmdp.dealer.masterinfo.dao.IMasterFileDao#getMasterFileInfoByFileName(com.cap.bts.crmdp.dealer.masterinfo.dto.MasterFileDto)
     */
    @Override
    public MasterFileModel getMasterFileInfoByFileName(MasterFileDto masterFileDto)
                                                                                   throws AppException {
        String sqlString = "select * from tm_master_file where file_name=?1";
        MasterFileModel masterFileModel = null;

        List<MasterFileModel> masterFileList = super.getListByNativeQueryWithVaParam(sqlString,
            masterFileDto.getFileName());
        if (!masterFileList.isEmpty()) {
            masterFileModel = masterFileList.get(0);
            return masterFileModel;
        }
        return null;

    }

    /**
     * 保存同步的文件属性信息
     * @see com.cap.bts.crmdp.dealer.masterinfo.dao.IMasterFileDao#insertMasterFileInfo(com.cap.bts.crmdp.dealer.masterinfo.domain.MasterFileModel)
     */
    @Override
    public MasterFileModel insertMasterFileInfo(MasterFileModel masterFileModel)
                                                                                throws AppException {
        save(masterFileModel);
        return null;
    }
}
